import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import util from '@/until'


let router = new VueRouter({
    routes: [
        {
            path: '/home',
            component: () => import(/* webpackChunkName: "group-main" */ '../view/home.vue'),

            children: [, {
                path: 'main',
                component: () => import(/* webpackChunkName: "group-main" */ '../compents/main.vue'),
            }, {
                path: 'table',
                component: () => import(/* webpackChunkName: "group-table" */ '../compents/details/table.vue')
            }, {
                path: 'details',
                component: () => import(/* webpackChunkName: "group-details" */ '../compents/details/details.vue')
            }, {
                path: 'order',
                component: () => import(/* webpackChunkName: "group-order" */ '../compents/order/order.vue')
            }, {
                path: 'fahuo',
                component: () => import(/* webpackChunkName: "group-fahuo" */ '../compents/order/fahuo.vue')
            }, {
                path: 'changeadd',
                component: () => import(/* webpackChunkName: "group-changeadd" */ '../compents/order/changeadd.vue')
            }, {
                path: 'return_goods',
                component: () => import(/* webpackChunkName: "group-return_goods" */ '../compents/order/return_goods'),
            }, {
                path: 'return_details',
                component: () => import(/* webpackChunkName: "group-return_details" */ '../compents/order/return_details'),
            }, {
                path: 'user',
                component: () => import(/* webpackChunkName: "group-main" */ '../compents/user/usertable'),
            }, {
                path: 'watch_gong',
                component: () => import(/* webpackChunkName: "group-watch_gong" */ '../compents/gonghuo/watch'),
            }, {
                path: 'miaosha',
                component: () => import(/* webpackChunkName: "group-miaosha" */ '../compents/activity/miaosha'),
            }],
        },
        {
            path: '/', redirect: '/login'
        },
        {
            path: '/login',
            component: () => import(/* webpackChunkName: "group-login" */ '../view/login/login'),
        },


    ]
})
router.beforeEach((to, from, next) => {

    if (to.path != '/login') {
        if (!util.locastorage.get()) {
            return next('/login')
        }
    }

    NProgress.start();
    setTimeout(function () {
        NProgress.set(0.4)
    }, 500)
    setTimeout(function () {
        next()
    }, 500)
})
router.afterEach((to, from) => {
    NProgress.inc()
    setTimeout(function () {
        NProgress.done()
    }, 500)
})

export default router
